//
//  AppURL.swift
//  APP
//
//  Created by Rdxer on 2017/12/11.
//  Copyright © 2017年 Rdxer. All rights reserved.
//

import UIKit


/// 拼接 URL
extension AppURL{
    
    /// 业务数据 -  USERNAME LIGHT_PAW ORG_CODE  dataTemplate  四个
    static func makeDataAddressURL(USERNAME:String, LIGHT_PAW:String, ORG_CODE:String,  dataTemplate:String)->String{
        return String.init(format: Data_Address, USERNAME,LIGHT_PAW,ORG_CODE,dataTemplate)
    }
    /// 头像URL
    static func makeHeadURL(staHead:String?)->URL?{
        let headURL = try! AppURL.HeadURLString.asURL()
        if let staHead = staHead{
            let url = headURL.appendingPathComponent(staHead)
            return url
        }
        return nil
    }
    /// 图标URL
    static func makeIconURL(sta:String?)->URL?{
        let url1 = try! AppURL.IconURLString.asURL()
        if let sta = sta{
            let url = url1.appendingPathComponent(sta)
            return url
        }
        return nil
    }
    
}

open class AppURL:NSObject {

    /// 服务器
    static var HostURLString:String = SERVER_HOST //_TEST
    
    /// 头像
    static var HeadURLString:String = HEAD_HOST //_TEST
    
    /// 业务数据URL
    static var Data_Address:String = DATA_ADDRESS //_TEST
    
    static var IconURLString:String = COMMON_MODULE_ICON_PREFIX //_TEST
    
    static func initialize(isTestServer:Bool = false){
        if isTestServer {
            AppURL.HostURLString = AppURL.SERVER_HOST_TEST
            AppURL.HeadURLString = AppURL.HEAD_HOST_TEST
            AppURL.Data_Address = AppURL.DATA_ADDRESS_TEST
            AppURL.IconURLString = AppURL.COMMON_MODULE_ICON_PREFIX_TEST
        }else{
            AppURL.HostURLString = AppURL.SERVER_HOST
            AppURL.HeadURLString = AppURL.HEAD_HOST
            AppURL.Data_Address = AppURL.DATA_ADDRESS
            AppURL.IconURLString = AppURL.COMMON_MODULE_ICON_PREFIX
        }
    }
    
    //////////////////////////////////////////////////////////////////////
    /////////////////////////   配置信息   ////////////////////////////////
    //////////////////////////////////////////////////////////////////////
    
    /// 服务器 --------------------------------------------------
    fileprivate static let SERVER_HOST_TEST = "https://testsoa.firstcare.com.cn/rest/"
    fileprivate static let SERVER_HOST = "https://mobile.firstcare.com.cn/rest"
    
    /// 头像目录 --------------------------------------------------
    fileprivate static let HEAD_HOST_TEST = "https://testhr.firstcare.com.cn/upload/staffHead/"
    fileprivate static let HEAD_HOST = "https://hr.firstcare.com.cn/upload/staffHead/"
    
    /// 业务数据 --------------------------------------------------
    fileprivate static let DATA_ADDRESS_TEST = "https://testcas.firstcare.com.cn/firstcare/casClientLogin.jsp?username=%@&password=%@&orgCode=%@&casLoginKey=aph2_cas_redragon&service=%@"
    fileprivate static let DATA_ADDRESS = "https://cas.firstcare.com.cn/firstcare/casClientLogin.jsp?username=%@&password=%@&orgCode=%@&casLoginKey=aph2_cas_redragon&service=%@"
    
    /// 图标
    fileprivate static let COMMON_MODULE_ICON_PREFIX_TEST = "https://testsoa.firstcare.com.cn/";
    fileprivate static let COMMON_MODULE_ICON_PREFIX = "https://mobile.firstcare.com.cn/";
    
    /// ⬆️⬆️⬆️⬆️ USERNAME LIGHT_PAW ORG_CODE  dataTemplate ⬆️⬆️⬆️⬆️
}

